﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dycox.Validation;

namespace Dycox.Workflows.Conditions
{
    public abstract class ValidatorBasedCondition : TransitionCondition
    {
        public ValidatorBasedCondition()
            : base()
        {

        }

        protected abstract Validator Validator { get; }

        internal protected override bool Test(ConditionTestArguments args)
        {
            Validator val = Validator;
            object value = GetValidationValue(args);
            if (value != null)
            {
                return val.IsValid(value) != ValidationResult.Invalid;
            }
            else
                return false;
        }

        protected abstract object GetValidationValue(ConditionTestArguments args);

    }
}
